//
//  HX_City.m
//  09-省市区
//
//  Created by 韩旭 on 16/7/26.
//  Copyright © 2016年 lanou. All rights reserved.
//

#import "HX_City.h"
#import "Model.h"
#import "HX_Model.h"
#import "HX_Areas.h"
@interface HX_City ()<UITableViewDataSource, UITableViewDelegate>
@property (nonatomic, strong) UITableView *tableCity;
@property (nonatomic, strong) NSMutableArray *arrDataCitys;
@property (nonatomic, strong) NSMutableArray *arrDataSource;

@end

@implementation HX_City

- (NSMutableArray *)arrCity {
    if (!_arrCity) {
        self.arrCity = [NSMutableArray array];
    }
    return _arrCity;
}
- (NSMutableArray *)arrDataCitys {
    if (!_arrDataCitys) {
        self.arrDataCitys = [NSMutableArray array];
    }
    return _arrDataCitys;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"市";
    self.tableCity = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, kWidth, kHeight) style:0];
    [self creatArray];
    _tableCity.backgroundColor = [UIColor whiteColor];
    _tableCity.delegate = self;
    _tableCity.dataSource = self;
    [self.view addSubview:_tableCity];
}
- (void)creatArray {
    for (NSDictionary *dic in _arrCity) {
        HX_Model *model = [HX_Model personWithDic:dic];
        model.Ares = dic[@"Ares"];
        [self.arrDataCitys addObject:model];
    }
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _arrDataCitys.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *ID = @"cell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[UITableViewCell alloc] initWithStyle:3 reuseIdentifier:ID];
        
    }
    HX_Model *model = self.arrDataCitys[indexPath.row];
    cell.textLabel.text = model.ACityNames;
    cell.backgroundColor = [UIColor whiteColor];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    HX_Areas *areas = [[HX_Areas alloc] init];
    HX_Model *model = self.arrDataCitys[indexPath.row];
    areas.arrAreas = [model.Ares mutableCopy];
    [self.navigationController pushViewController:areas animated:YES];
}

@end
